﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.FactionManagerStancesData
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem
{
  internal class FactionManagerStancesData
  {
    [SaveableField(10)]
    private Dictionary<(IFaction, IFaction), StanceLink> _stances = new Dictionary<(IFaction, IFaction), StanceLink>();

    internal static void AutoGeneratedStaticCollectObjectsFactionManagerStancesData(
      object o,
      List<object> collectedObjects)
    {
      ((FactionManagerStancesData) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      collectedObjects.Add((object) this._stances);
    }

    internal static object AutoGeneratedGetMemberValue_stances(object o)
    {
      return (object) ((FactionManagerStancesData) o)._stances;
    }

    public Dictionary<(IFaction, IFaction), StanceLink>.ValueCollection GetStanceLinks()
    {
      return this._stances.Values;
    }

    internal StanceLink GetStance(IFaction faction1, IFaction faction2)
    {
      StanceLink stance;
      this._stances.TryGetValue(this.GetKey(faction1, faction2), out stance);
      return stance;
    }

    public void AddStance(StanceLink stance)
    {
      (IFaction, IFaction) key = this.GetKey(stance);
      if (this._stances.ContainsKey(key))
        this._stances[key] = stance;
      else
        this._stances.Add(key, stance);
    }

    public void RemoveStance(StanceLink stance)
    {
      (IFaction, IFaction) key = this.GetKey(stance);
      if (!this._stances.ContainsKey(key))
        return;
      this._stances.Remove(key);
    }

    private (IFaction, IFaction) GetKey(IFaction faction1, IFaction faction2)
    {
      return faction1.Id < faction2.Id ? (faction1, faction2) : (faction2, faction1);
    }

    private (IFaction, IFaction) GetKey(StanceLink stance)
    {
      return this.GetKey(stance.Faction1, stance.Faction2);
    }
  }
}
